import { onMounted, onUnmounted } from 'vue'
import { useSocketStore } from '@/store/useSocketStore'

export function useSocketEvent<T>(
    event: string,
    callback: (data: T) => void
) {
    const socketStore = useSocketStore()

    onMounted(() => {
        socketStore.on(event, callback)
    })

    onUnmounted(() => {
        socketStore.off(event, callback)
    })

    return {
        emit: (data: T) => socketStore.emit(event, data),
    }
}